package com.chinasofti.optional;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class Demo03 {
    public static void main(String[] args) {
//        method1();
        Student s = new Student("asd",32);
//        s=null;
        Optional optional = Optional.ofNullable(s);

        optional.ifPresent(new Consumer() {
            @Override
            public void accept(Object o) {
                Student s1 = (Student)o;
                System.out.println(s1);
            }
        });
    }



    private static void method1() {
        Student s = new Student("asd",32);
        s=null;
        Optional optional = Optional.ofNullable(s);
        System.out.println(optional.orElseGet(new Supplier() {
            @Override
            public Object get() {
                return new Student("s",12);
            }
        }));
        System.out.println(s);
    }
}
